﻿using System;
using System.Web;
using System.Web.UI;

namespace gms.security {
	public class ErrorHandler : IHttpModule {
		public void Dispose() { }
		public void Init(HttpApplication context) {
			context.Error += new EventHandler(context_Error);
		}
		public void context_Error(object sender, EventArgs e) {
			HttpContext context = ((HttpApplication)sender).Context;
			Exception[] last_ex = context.AllErrors;

			if (last_ex != null) {
				context.Response.Write("An error has occurred!<hr />");

				for (int i = 0; i < last_ex.Length; i++) {
					if (last_ex[i].InnerException != null) {
						context.Response.Write(last_ex[i].InnerException.Message + "<br />");
					}
					else {
						context.Response.Write(last_ex[i].Message + "<br />");
					}
				}
			}

			context.ClearError();
		}
	}
}